home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / Asm / Demos / Stars8.s < prev    next >
Encoding:
Text File  |  1997-05-02  |  6.9 KB  |  304 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;3D STARFIELD 8
  3. ;--------------
  4. ;Same as the first starfield demo but runs in 8 colours.  Default is 500
  5. ;stars which runs fine on my A1200+Fast - but try 5000 stars or more for a
  6. ;real visual experience :-)
  7.  
  8.     INCDIR    "INCLUDES:"
  9.     INCLUDE    "games/games_lib.i"
  10.     INCLUDE    "games/games.i"
  11.  
  12. CALL    MACRO
  13.     jsr    _LVO\1(a6)
  14.     ENDM
  15.  
  16. NSTARS    =    700    ;Number of stars
  17.  
  18. XSPEED    =    -4
  19. YSPEED    =    6
  20. ZSPEED    =    2
  21.  
  22. SCR_HEIGHT =    256
  23. SCR_WIDTH =    320
  24.  
  25.     SECTION    "Stars",CODE
  26.  
  27. ;==========================================================================;
  28. ;                             INITIALISE DEMO
  29. ;==========================================================================;
  30.  
  31.     STARTGMS
  32.  
  33. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  34.     move.l    GMSBase(pc),a6
  35.     lea    ScreenTags(pc),a0
  36.     CALL    ShowScreen
  37.     tst.l    d0
  38.     beq.s    .Error_Screen
  39.  
  40.     bsr.s    Main
  41.  
  42. .ReturnToDOS
  43.     move.l    GMSBase(pc),a6
  44.     move.l    Screen(pc),a0
  45.     CALL    DeleteScreen
  46. .Error_Screen
  47.     MOVEM.L    (SP)+,A0-A6/D1-D7
  48.     moveq    #ERR_OK,d0
  49.     rts
  50.  
  51. ;==========================================================================;
  52. ;
  53. ;==========================================================================;
  54.  
  55.     ;Randomize star coordinates
  56.  
  57. Main:    lea    StarCoords,a0    ;a0 = Ptr to star co-ordinates.
  58.     move.w    #NSTARS-1,d7
  59. .loop1    move.w    #8192,d1
  60.     CALL    SlowRandom
  61.     move.w    d0,(a0)+
  62.     CALL    SlowRandom
  63.     move.w    d0,(a0)+
  64.     CALL    SlowRandom
  65.     move.w    d0,(a0)+
  66.     dbra    d7,.loop1
  67.  
  68.     ;Construct perspective table
  69.  
  70.     lea    PersTable,a0    ;a0 = ptr to perspective table.
  71.     moveq    #0,d1    ;d1 = Starting at 0.
  72. .loop2    move.l    #$95FFFF,d2    ;d2 = $95FFFF
  73.     move.l    d1,d3    ;d3 = d1
  74.     add.w    #300,d3    ;d3 = ++300
  75.     divu    d3,d2    ;d2 = ($95ffff)/d3
  76.     move.w    d2,(a0)+    ;a0 = d2+
  77.     addq.w    #1,d1    ;d1 = ++1
  78.     cmp.w    #8192,d1    ;d1 = Equal to 8192?
  79.     bne.s    .loop2
  80.  
  81.     ;Construct plot tables for fast drawing.
  82.  
  83.     lea    PlotXTable,a0    ;a0 = X table - byte positions.
  84.     lea    PlotBTable,a1    ;a1 = Bit table (X related).
  85.     lea    PlotYTable,a2    ;a2 = Y table - line position.
  86.     moveq    #0,d0    ;d0 = 00
  87. .loop3    move.w    d0,d1    ;d1 = d0
  88.     lsr.w    #3,d1    ;d1 = (d0)<<3
  89.     move.w    d1,(a0)+    ;a0 = d1+
  90.  
  91.     move.w    d0,d1    ;d1 = d0
  92.     eor.w    #$FFFF,d1    ;d1 = (d0) eor $ffff
  93.     and.w    #%00000111,d1    ;d1 = &%00000111
  94.     move.w    d1,(a1)+    ;a1 = BitSet++
  95.  
  96.     cmp.w    #SCR_HEIGHT,d0    ;Write out the Y values for the
  97.     bge.s    .plot2    ;table.
  98.     move.w    d0,d1    ;d1 = Line Number.
  99.     mulu    #120,d1    ;d1 = (LineNumber)*80
  100.     move.w    d1,(a2)+    ;a2 = (LineNumber*80)++
  101.  
  102. .plot2    addq.w    #1,d0
  103.     cmp.w    #SCR_WIDTH,d0
  104.     bne.s    .loop3
  105.  
  106. ;==========================================================================;
  107. ;                                MAIN LOOP
  108. ;==========================================================================;
  109.  
  110. MainLoop:
  111.     move.l    GMSBase(pc),a6
  112.     move.l    Screen(pc),a0
  113.     CALL    WaitVBL
  114.     CALL    SwapBuffers
  115.  
  116. ;==========================================================================;
  117. ;                             STAR ANIMATION
  118. ;==========================================================================;
  119.  
  120.     movem.w    StarXPos(pc),d0/d1/d2    ;MV = d0/d1/d2 = XPos/YPos/ZPos
  121.     add.w    #XSPEED,d0    ;d0 = (StarXPos)+XSPEED
  122.     add.w    #YSPEED,d1    ;d1 = (StarYPos)+YSPEED
  123.     add.w    #ZSPEED,d2    ;d2 = (StarZPos)+ZSPEED
  124.     and.w    #%0000011111111111,d0
  125.     and.w    #%0000011111111111,d1
  126.     and.w    #%0000011111111111,d2
  127.     movem.w    d0/d1/d2,StarXPos
  128.  
  129.     lea    Sinus(pc),a0    ;a0 = Sinus table.
  130.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : X/Y/Z
  131.     add.w    (a0,d0.w),d3
  132.     add.w    (a0,d1.w),d4
  133.     add.w    (a0,d2.w),d5
  134.     movem.w    d3/d4/d5,StarXAdd
  135.  
  136. ;===========================================================================;
  137. ;                              SCREEN CLEAR
  138. ;===========================================================================;
  139. ;Let the blitter clear our 3rd screen while the CPU draws the stars.
  140.  
  141.     move.l    GMSBase(pc),a6
  142.     move.l    Screen(pc),a0
  143.     moveq    #BUFFER3,d0
  144.     CALL    ClrScreen
  145.  
  146. ;==========================================================================;
  147. ;                               DRAW STARS
  148. ;==========================================================================;
  149.  
  150.     lea    StarCoords,a0    ;Draw starfield
  151.     lea    PersTable,a1    ;a1 = Perspective table.
  152.     lea    PlotXTable,a2    ;a2 = X table.
  153.     lea    PlotBTable,a3    ;a3 = Bit table.
  154.     lea    PlotYTable,a4    ;a4 = Y table.
  155.  
  156.     move.l    Screen(pc),a6
  157.     move.l    GS_MemPtr2(a6),a6
  158.  
  159.     movem.w    StarXAdd(pc),d3/d4/d5    ;MV = d3/d4/d5 : ?
  160.     add.w    #4096,d3    ;d3 = ++4096
  161.     add.w    #4096,d4    ;d4 = ++4096
  162.  
  163.     move.w    #NSTARS-1,d7
  164.  
  165. .draw    movem.w    (a0)+,d0/d1/d2    ;MV = d0/d1/d2 : XPos/YPos/ZPos.
  166.     add.w    d3,d0    ;Increase XPos.
  167.     and.w    #8191,d0    ;d0 = And'd
  168.     sub.w    #4096,d0    ;d0 = --4096
  169.  
  170.     add.w    d4,d1    ;Y-movement
  171.     and.w    #8191,d1    ;d1 = And'd
  172.     sub.w    #4096,d1    ;d1 = --4096
  173.  
  174.     add.w    d5,d2    ;Z-movement
  175.     and.w    #8191,d2
  176.     add.w    d2,d2    ;d2 = *2 [word]
  177.     move.w    (a1,d2.w),d6    ;d6 = Read from Perspective table.
  178.  
  179.     muls    d6,d0    ;X-projection
  180.     swap    d0
  181.     add.w    #176,d0
  182.  
  183.     cmp.w    #SCR_WIDTH-1,d0
  184.     bhi    .nodraw
  185.     muls    d6,d1    ;Y-projection
  186.     swap    d1
  187.     add.w    #136,d1
  188.     cmp.w    #SCR_HEIGHT-1,d1
  189.     bhi    .nodraw
  190.  
  191.     add.w    d0,d0    ;d0 = *2 [word]
  192.     add.w    d1,d1    ;d1 = *2 [word]
  193.     move.w    (a4,d1.w),d6    ;d6 = Plot Y.
  194.     add.w    (a2,d0.w),d6    ;d6 = ++PlotX.
  195.     move.w    (a3,d0.w),d0    ;d0 = BitValue.
  196.  
  197. .draw1    cmp.w    #4000,d2    ;Now draw the star according to
  198.     bgt.s    .draw2    ;its position in the Z axis.
  199.     bset    d0,(a6,d6.w)
  200.     dbra    d7,.draw
  201.     bra.s    .done
  202.  
  203. .draw2    cmp.w    #6000,d2
  204.     bgt.s    .draw3
  205.     bset    d0,40(a6,d6.w)
  206.     dbra    d7,.draw
  207.     bra.s    .done
  208.  
  209. .draw3    cmp.w    #8000,d2
  210.     bgt.s    .draw4
  211.     bset    d0,(a6,d6.w)
  212.     bset    d0,40(a6,d6.w)
  213.     dbra    d7,.draw
  214.     bra.s    .done
  215.  
  216. .draw4    cmp.w    #10000,d2
  217.     bgt.s    .draw5
  218.     bset    d0,80(a6,d6.w)
  219.     dbra    d7,.draw
  220.     bra.s    .done
  221.  
  222. .draw5    cmp.w    #12000,d2
  223.     bgt.s    .draw6
  224.     bset    d0,(a6,d6.w)
  225.     bset    d0,80(a6,d6.w)
  226.     dbra    d7,.draw
  227.     bra.s    .done
  228.  
  229. .draw6    cmp.w    #14000,d2
  230.     bgt.s    .draw7
  231.     bset    d0,40(a6,d6.w)
  232.     bset    d0,80(a6,d6.w)
  233.     dbra    d7,.draw
  234.     bra.s    .done
  235.  
  236. .draw7    bset    d0,(a6,d6.w)
  237.     bset    d0,40(a6,d6.w)
  238.     bset    d0,80(a6,d6.w)
  239. .nodraw    dbra    d7,.draw
  240.  
  241. .done    move.l    GMSBase(pc),a6
  242.     moveq    #JPORT1,d0    ;Read from port 1 (mouse).
  243.     moveq    #JT_ZBXY,d1
  244.     CALL    ReadJoyPort    ;Go get port status.
  245.     btst    #MB_LMB,d0
  246.     beq    MainLoop
  247.     rts
  248.  
  249. ;===========================================================================;
  250. ;                                  DATA
  251. ;===========================================================================;
  252.  
  253. ScreenTags:
  254.     dc.l    TAGS_GAMESCREEN
  255. Screen:    dc.l    0
  256.     dc.l    GSA_Palette,.palette
  257.     dc.l    GSA_ScrWidth,320
  258.     dc.l    GSA_ScrHeight,256
  259.     dc.l    GSA_Planes,3
  260.     dc.l    GSA_Attrib,TPLBUFFER
  261.     dc.l    GSA_ScrMode,LORES
  262.     dc.l    GSA_ScrType,ILBM
  263.     dc.l    TAGEND
  264.  
  265. .palette
  266.     dc.l    $000000,$f0f0f0,$c0c0c0,$909090 ;%000, %100, %010, %110
  267.     dc.l    $707070,$505050,$303030,$101010 ;%001, %101, %011, %111
  268.  
  269. ;===========================================================================;
  270. ;                                STAR DATA
  271. ;===========================================================================;
  272.  
  273. StarXAdd
  274.     dc.w    33    ;Star stuff
  275. StarYAdd
  276.     dc.w    12
  277. StarZAdd
  278.     dc.w    -114
  279.  
  280. StarXPos
  281.     dc.w    0    ;Sinus positions
  282. StarYPos
  283.     dc.w    310
  284. StarZPos
  285.     dc.w    1280
  286.  
  287.     INCLUDE    "GMS:source/asm/demos/StarSinus.i"
  288.  
  289.     SECTION    Storage,BSS
  290.  
  291. StarCoords
  292.     ds.w    NSTARS*3    ;Star coordinates
  293.  
  294. PersTable
  295.     ds.w    8192    ;Perspective table
  296.  
  297. PlotXTable
  298.     ds.w    SCR_WIDTH    ;Plot tables
  299. PlotBTable
  300.     ds.w    SCR_WIDTH
  301. PlotYTable
  302.     ds.w    SCR_HEIGHT
  303.  
  304.